package com.fl.boot.controller;

import com.fl.boot.entity.Result;
import com.fl.boot.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

/**
 * Author: FL
 * Date: 2024/2/6 16:04
 */
@RestController
@Slf4j
public class TestController {
    //    无参测试
    @RequestMapping(value = "/test")
    public String test() {
        log.info("这是一个信息日志，通常用于记录应用程序的正常运行情况。");
        log.debug("这是一个调试日志，通常用于开发阶段的诊断。");
        log.warn("这是一个警告日志，用于记录不正常或不期望的情况。");
//        log.error("这是一个错误日志，用于记录严重的错误情况。", e); // e 是一个异常对象
        return "Hello, world!";
    }

    @RequestMapping("/hello")
    public Result hello() {
        return Result.success("Hello, world!");
    }

    //    简单参数绑定测试
    @RequestMapping("/simpleParam")
    public String simpleParam(String name, Integer age) {
        log.info("name={}, age={}", name, age);
        return "OK";
    }

    //    简单的实体类参数绑定测试
    @RequestMapping("/simpleEntity")
    public String simpleEntity(User user) {
        log.info(user.toString());
        return "OK";
    }

    //    复杂的实体类参数绑定测试
    @RequestMapping("/complexEntity")
    public String complexEntity(User user) {
       log.info(user.toString());
        return "OK";
    }

//    数组参数绑定测试
    @RequestMapping("/arrayParam")
    public String arrayParam(@RequestParam(value = "hobby") String[] hobbies){
       log.info(Arrays.toString(hobbies));
        return "OK";
    }

    // 集合参数绑定测试
    @RequestMapping("/listParam")
    public String listParam(@RequestParam(value = "hobby") List<String> hobbies){
        log.info(hobbies.toString());
        return "OK";
    }

//    json参数绑定测试
    @RequestMapping("/jsonParam")
    public ResponseEntity<User> jsonParam(@RequestBody User user){
        log.info(user.toString());
        return ResponseEntity.ok(user);
    }
}
